package net.huashitong.supervision.AppNew.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import net.huashitong.supervision.AppNew.DTO.viewDto.NumCount;
import net.huashitong.supervision.task.entity.TaskMain;
import net.huashitong.supervision.task.entity.TaskUnit;
import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
@Qualifier("apptaskmain")
public class AppTaskUnitDao extends StringDao<TaskMain>  {

    /**
     * 首页总数
     * @return
     */
    public List<NumCount>  getSendAndFinish()
    {
        StringBuffer sql = new StringBuffer();
        sql.append(" select  count(1) as nums , status as names ");
        sql.append(" from t_task_main ");
        sql.append(" group by  status ");

       // GenericQuery query  = create( sql.toString());
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(NumCount.class));
        List<NumCount>  list =(List<NumCount>) query.list();

        return list;


    }

    /**
     * 任务分类
     * @return
     */
    public List<NumCount> getCategoryNum()
    {
        StringBuffer sql = new StringBuffer();
        sql.append(" select  count(1) as nums ,category_id as  names ");
        sql.append(" from t_task_main ");
        sql.append(" group by  category_id ");

        // GenericQuery query  = create( sql.toString());
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(NumCount.class));
        List<NumCount>  list =(List<NumCount>) query.list();

        return list;

    }

    public List<NumCount> getWeekUnitNum( String StringDate){

        StringBuffer sql = new StringBuffer();
        sql.append("select  count(1) nums,type  names ");
        sql.append(" from t_task_unit ");
        sql.append("where task_main_id  in");
        sql.append("(select  sys_id ");
        sql.append("from  t_task_main ");
        sql.append("where STR_TO_DATE(create_date,'%Y-%m-%d')>STR_TO_DATE('"+ StringDate +"','%Y-%m-%d') ORDER BY sys_id desc ) ");
        sql.append("GROUP BY type ");


        // GenericQuery query  = create( sql.toString());
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(NumCount.class));
        List<NumCount>  list =(List<NumCount>) query.list();

        return  list;
    }



}
